<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title> 审核规则控制</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link rel="shortcut icon" href="__PUBLIC__/admin/favicon.ico">
    <link href="__PUBLIC__/admin/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="__PUBLIC__/admin/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="__PUBLIC__/admin/css/animate.css" rel="stylesheet">
    <link href="__PUBLIC__/admin/css/style.css?v=4.1.0" rel="stylesheet">
    <link href="__PUBLIC__/admin/js/plugins/fancybox/jquery.fancybox.css" rel="stylesheet">
    <link href="__PUBLIC__/admin/js/plugins/iCheck/custom.css" rel="stylesheet">
    <!--<link href="__PUBLIC__/admin/js/layui/css/layui.css" rel="stylesheet">-->

</head>
<include file="Admin@Index:cache" />
<body class="gray-bg contacts" oncopy="copyval()">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox">
                <div class="ibox-content">
                    <h2>控制</h2>

                    <br>
                    <table class="table table-striped table-hover">
                        <tbody>
                        <tr>
                            <th>规则名称</th>
                            <th>规则详情</th>
                            <th>操作</th>
                        </tr>
                        <foreach name="list" item="list">
                            <tr>
                                <td><?= $list['rule_name'];?></td>
                                <td><?= $list['rule_detail'];?></td>
                                <td>  <a class="btn btn-success btn-rounded modify" href="javascript:void(0);"
                                         onclick="upd_rule_control('<{$list.id}>','<{$list.rule_detail}>','<{$list.rule_code}>')">修改</a></td>
                            </tr>
                        </foreach>
                        </tbody>
                    </table>
                    <ul class="pagination">
                        <if condition="$tol gt 10">
                        <{$fpage}>
                            </if>
                    </ul>
                    <!--<div data-toggle="distpicker">-->
                        <!--<select data-province="浙江省"></select>-->
                        <!--<select data-city="杭州市"></select>-->
                        <!--<select data-district="西湖区"></select>-->
                    <!--</div>-->
                </div>
            </div>
        </div>
    </div>
</div>
<style>
    .m-b{
        height: 3rem;
        width:45%;
        float:left
    }
</style>
<!-- 全局js -->
<script src="__PUBLIC__/admin/js/jquery.min.js?v=2.1.4"></script>
<script src="__PUBLIC__/admin/js/bootstrap.min.js?v=3.3.6"></script>
<script src="__PUBLIC__/admin/js/layer/layer.js"></script>
<script src="__PUBLIC__/admin/js/layui/layui.js"></script>
<script src="__PUBLIC__/admin/js/layui/lay/modules/laydate.js"></script>
<!--<script src="__PUBLIC__/admin/js/layui/lay/dest/layui.all.js"></script>-->
<!-- 自定义js -->
<script src="__PUBLIC__/admin/js/content.js?v=1.0.0"></script>
<script src="__PUBLIC__/admin/js/plugins/fancybox/jquery.fancybox.js"></script>
<script src="__PUBLIC__/admin/address/js/distpicker.data.js"></script>
<script src="__PUBLIC__/admin/address/js/distpicker.js"></script>
<script src="__PUBLIC__/admin/address/js/main.js"></script>

<script>
    $(document).ready(function () {
        $('.contact-box').each(function () {
            animationHover(this, 'pulse');
        });
    });

    function upd_rule_control(id,detail,code){
        switch(code){
            //年龄限制
            case 'K0001':
                    age_control(id,detail,code);
                    break;
            //地区限制
            case 'K0031':
                    address_control(id,detail,code);
                    break;
            //职业限制
            case 'K0035':
                    vocation_control(id,detail,code);
                    break;
            //入网时间限制
            case 'K0005':
                    time_control(id,detail,code);
                    break;
            //芝麻认证是否开启
            case 'K0042':
                    zhima_control(id,detail,code);
                    break;
        }
    }

    function sub(id,code){
        layer.confirm('是否确定修改？', function () {
            switch(code){
                //年龄限制
                case 'K0001':
                        var min_age=$('#min_age').val();
                        var max_age=$('#max_age').val();
                        if(min_age<=0 || max_age<=0){
                            layer.msg('年龄不得小于等于0', {time: 2000, icon: 5});
                            return false;
                        }
                        var detail=min_age+','+max_age;
                        break;
                //地区限制
                case 'K0031':
                        var detail='';
                        var pro='';
                        var city='';
                        $('.province').each(function(k,v){
                            pro=$(this).val();
                            city=$(this).next().val();
                            if(city==''){
                                city=0;
                            }
                            if(k==0){
                                detail=pro+'-'+city;
                            }else{
                                detail+=','+pro+'-'+city;
                            }
                        });
//                        console.log(detail);
//                        return false;
                        break;
                //职业限制
                case 'K0035':
                        var detail='';
                        $('.vocation').each(function(k,v){
                            if(k==0){
                                detail=$(this).val();
                            }else if($(this).val()!=''){
                                detail+=','+$(this).val();
                            }
                        });
                        break;
                //入网时间限制
                case 'K0005':
                        var detail=$('#time').val();
                    break;
                //芝麻认证是否开启
                case 'K0042':
                        var detail=$('#zhima').val();
                    break;
            }
            layer.load(2);
            $.post('__MODULE__/Systems/upd_rule_control', {
                id:id,
                detail:detail
            }, function (data) {
                layer.closeAll('loading');
                if (data.code == '1001') {
                    layer.closeAll();
                    layer.msg(data.result,{icon: 1,time:1000}, function(){
                        window.location.reload();
                    });
                } else {
                    if (data.status == '0') {
                        layer.msg(data.info, {time: 2000, icon: 5});
                    } else {
                        layer.msg(data.result, {time: 2000, icon: 5});
                    }
                }
            });
        });
    }

    function age_control(id,detail,code) {
        var age=detail.split(',');
        var html = '';
        html += '<div class="modal-body" id="lists">';
        html += '<form class="form-horizontal">';
        html += '<div class="form-group">';
        html += '<label class="col-sm-5 control-label" >最小年龄：</label>';
        html += '<div class="col-sm-5">';
        html += '<input  id="min_age" value="'+age[0]+'" type="number" onblur="check_age(this.value,1)" autocomplete="off" class="form-control" />';
        html += '</div>';
        html += '</div>';
        html += '<div class="form-group">';
        html += '<label class="col-sm-5 control-label" >最大年龄：</label>';
        html += '<div class="col-sm-5">';
        html += '<input  id="max_age" value="'+age[1]+'" type="number"  onblur="check_age(this.value,2)" autocomplete="off" class="form-control" />';
        html += '</div>';
        html += '</div>';
        html += '</form>';
        html += '<div class="modal-footer" style="border:0">';
        html += '<a href="javascript:void(0);" onclick="layer.closeAll()" type="button" class="btn btn-default" >关闭</a>';
        html += '<a href="javascript:void(0);" onclick="sub(\''+id+'\',\''+code+'\');" type="button" class="btn btn-primary" >修改</a>';
        html += '</div>';
        html += '</div>';

        layer.open({
            type: 1, //Page层类型
            area: ['400px', '255px'],
            title: '年龄限制修改',
            shade: 0.6, //遮罩透明度
            maxmin: true, //允许全屏最小化
            anim: 1, //0-6的动画形式，-1不开启
            content: html
        });
    }


    function check_age(age,type){
        switch(type){
            case 1:
                var age_end=$('#max_age').val();
                if(age_end*1<=age*1){
                    console.log(age);
                    $('#max_age').val('');
                }
                break;
            case 2:
                var age_start=$('#min_age').val();
                if(age*1<=age_start*1){
                    $('#min_age').val('');
                }
                break;
        }
    }

    function address_control(id,detail,code) {
        var detail=detail.split(',');
        var html = '';
        html += '<div class="modal-body" id="lists">';
        html += '<form class="form-horizontal" id="address">';
        $(detail).each(function(key,value){
            if(value!=''){
                var address=value.split('-');
                if(address[1]==0 || address[1]==undefined){
                    address[1]='---- 选择市 ----';
                }
                html += '<div class="form-group">';
                html += '<label class="col-sm-2 control-label" >黑名单地区：</label>';
                html += '<div class="col-sm-8">';
                html += '<div data-toggle="distpicker">';
                html += '<select  class="form-control m-b province" data-province="'+address[0]+'"></select>';
                html += '<select  class="form-control m-b" style="margin-left: 5px;width:50%" data-city="'+address[1]+'"></select>';
                html += '</div>';
                html += '</div>';
                html += '<div class="col-sm-2" style="width:10%;padding: 0">';
                html += '<a href="javascript:void(0);" style="width:35px;" onclick="del_address(this)" type="button" class="btn btn-danger" > X </a>';
                html += '</div>';
                html += '</div>';
            }
        });
        html += '</form>';
        html += '<div class="modal-footer" style="border:0">';
        html += '<a href="javascript:void(0);"  type="button" onclick="add_address()" class="btn btn-success" >+</a>';
        html += '<a href="javascript:void(0);" onclick="layer.closeAll()" type="button" class="btn btn-default" >关闭</a>';
        html += '<a href="javascript:void(0);" onclick="sub(\''+id+'\',\''+code+'\');" type="button" class="btn btn-primary" >修改</a>';
        html += '</div>';
        html += '</div>';
        layer.open({
            type: 1, //Page层类型
            area: ['680px', '500px'],
            title: '修改地区限制',
            shade: 0.6, //遮罩透明度
            maxmin: true, //允许全屏最小化
            anim: 1, //0-6的动画形式，-1不开启
            content: html
        });
        $(function () {
            $('[data-toggle="distpicker"]').distpicker({
                autoSelect: false
            });
        });
    }

    function del_address(t){
        $(t).parent().parent().remove();
    }

    function add_address(){
        var html='';
        html += '<div class="form-group">';
        html += '<label class="col-sm-2 control-label" >黑名单地区：</label>';
        html += '<div class="col-sm-8">';
        html += '<div data-toggle="distpicker">';
        html += '<select  class="form-control m-b province" data-province=""></select>';
        html += '<select  class="form-control m-b" style="margin-left: 5px;width:50%" data-city=""></select>';
        html += '</div>';
        html += '</div>';
        html += '<div class="col-sm-2" style="width:10%;padding: 0">';
        html += '<a href="javascript:void(0);" style="width:35px;" onclick="del_address(this)" type="button" class="btn btn-danger" > X </a>';
        html += '</div>';
        html += '</div>';
        $('#address').append(html);
        $(function () {
            $('[data-toggle="distpicker"]').distpicker({
                autoSelect: false
            });

        });

    }

    function vocation_control(id,detail,code) {
        var vocation=detail.split(',');
        var len=vocation.length;
        var html = '';
        html += '<div class="modal-body" id="lists">';
        html += '<form class="form-horizontal" id="form">';
        $(vocation).each(function(k,v){
            if(v!=''){
                html += '<div class="form-group vo" >';
                html += '<label class="col-sm-3 control-label" >敏感职业：</label>';
                html += '<div class="col-sm-6">';
                html += '<input style="height: 2.5rem" class="form-control vocation" value="'+v+'" type="text" autocomplete="off" class="form-control" />';
                html += '</div>';
                html += '<div class="col-sm-2" style="width:10%;padding: 0">';
                html += '<a href="javascript:void(0);" style="width:35px;" onclick="del_vocation(this)" type="button" class="btn btn-danger" > X </a>';
                html += '</div>';
                html += '</div>';
            }
        });
        html += '</form>';
        html += '<div class="modal-footer" style="border:0">';
        html += '<a href="javascript:void(0);"  type="button" onclick="add_vocation()" class="btn btn-success" >+</a>';
        html += '<a href="javascript:void(0);" onclick="layer.closeAll()" type="button" class="btn btn-default" >关闭</a>';
        html += '<a href="javascript:void(0);" onclick="sub(\''+id+'\',\''+code+'\');" type="button" class="btn btn-primary" >修改</a>';
        html += '</div>';
        html += '</div>';

        layer.open({
            type: 1, //Page层类型
            area: ['430px', '455px'],
            title: '职业限制修改',
            shade: 0.6, //遮罩透明度
            maxmin: true, //允许全屏最小化
            anim: 1, //0-6的动画形式，-1不开启
            content: html
        });
    }
    function del_vocation(t){
        $(t).parent().parent().remove();
    }

    function add_vocation(){
        console.log($('.vo').length);
        var html='';
        html += '<div class="form-group vo" >';
        html += '<label class="col-sm-3 control-label" >敏感职业：</label>';
        html += '<div class="col-sm-6">';
        html += '<input style="height: 2.5rem" class="form-control vocation" value="" type="text" autocomplete="off" class="form-control" />';
        html += '</div>';
        html += '<div class="col-sm-2" style="width:10%;padding: 0">';
        html += '<a href="javascript:void(0);" style="width:35px;" onclick="del_vocation(this)" type="button" class="btn btn-danger" > X </a>';
        html += '</div>';
        html += '</div>';
        $('#form').append(html);
    }

    function time_control(id,detail,code) {
        var html = '';
        html += '<div class="modal-body" id="lists">';
        html += '<form class="form-horizontal">';
        html += '<div class="form-group">';
        html += '<label class="col-sm-7 control-label" >入网时间不得少于(单位月)：</label>';
        html += '<div class="col-sm-4">';
        html += '<input  id="time" style="height: 2.5rem;" value="'+detail+'" type="number"  autocomplete="off" class="form-control" />';
        html += '</div>';
        html += '</div>';
        html += '</form>';
        html += '<div class="modal-footer" style="border:0">';
        html += '<a href="javascript:void(0);" onclick="layer.closeAll()" type="button" class="btn btn-default" >关闭</a>';
        html += '<a href="javascript:void(0);" onclick="sub(\''+id+'\',\''+code+'\');" type="button" class="btn btn-primary" >修改</a>';
        html += '</div>';
        html += '</div>';

        layer.open({
            type: 1, //Page层类型
            area: ['400px', '235px'],
            title: '入网时间限制修改',
            shade: 0.6, //遮罩透明度
            maxmin: true, //允许全屏最小化
            anim: 1, //0-6的动画形式，-1不开启
            content: html
        });
    }

    function zhima_control(id,detail,code) {
        var html = '';
        html += '<div class="modal-body" id="lists">';
        html += '<form class="form-horizontal">';
        html += '<div class="form-group">';
        html += '<label class="col-sm-5 control-label" >芝麻认证：</label>';
        html += '<div class="col-sm-6">';
        html += '<select class="form-control m-b" name="zhima" id="zhima" style="height:3rem;width:60%">';
        switch(detail){
            case '开启':
                var gg='selected';
                break;
            case '关闭':
                var hh='selected';
                break;
        }
        html += '<option value="开启" '+gg+'>开启</option>';
        html += '<option value="关闭" '+hh+'>关闭</option>';
        html += '</select>';
        html += '</div>';
        html += '</div>';

        html += '</form>';
        html += '<div class="modal-footer" style="border:0">';
        html += '<a href="javascript:void(0);" onclick="layer.closeAll()" type="button" class="btn btn-default" >关闭</a>';
        html += '<a href="javascript:void(0);" onclick="sub(\''+id+'\',\''+code+'\');" type="button" class="btn btn-primary" >修改</a>';
        html += '</div>';
        html += '</div>';

        layer.open({
            type: 1, //Page层类型
            area: ['400px', '230px'],
            title: '芝麻认证修改',
            shade: 0.6, //遮罩透明度
            maxmin: true, //允许全屏最小化
            anim: 1, //0-6的动画形式，-1不开启
            content: html
        });
    }
//
//    function copyval() {
////        event.returnValue = false;
//        var content = window.getSelection().toString();
//        $.post('__MODULE__/Mypublic/copy_all', {content:content}, function (data) {
//            if (data.code == '1001') {
//            } else {
//                console.log(data);
//            }
//        });
//    }

</script>


</body>

</html>
